package negModel;

import negModelExcep.eParteNoFunciona;
import org.w3c.dom.Document;
import org.w3c.dom.Element;


public class Aleron extends ParteAerodinamica {

	private double parteSuperior; 
	private double parteInferior;
	private double largo;
	
	public Aleron (int vidaUtil, double peso,float aporteVelMax,String detalle,AlgoPesos precio,boolean removible,int aerodinamia,double largo, double pS, double pI){
		this.setMaxVU(vidaUtil);
		this.arreglar();
		this.setPeso(peso);
		this.setAportevmax(aporteVelMax);
		this.setDetalle(detalle);
		this.setPrecio(precio);
		this.setRemovible(removible);
		this.setAerodinamia(aerodinamia);
		
		this.parteInferior=pI;
		this.parteSuperior=pS;
		this.largo=largo;
	}
	
	public Aleron (Element xmlElement) {
		this.setMaxVU(Integer.parseInt(xmlElement.getAttribute("maxVU")));
		this.setVidaUtil(Integer.parseInt(xmlElement.getAttribute("vidaUtil")));
		this.setPeso(Double.parseDouble(xmlElement.getAttribute("peso")));
		this.setAportevmax(Float.parseFloat(xmlElement.getAttribute("aportevmax")));
		this.setDetalle(xmlElement.getAttribute("detalle"));
		this.setPrecio(new AlgoPesos(Double.parseDouble(xmlElement.getAttribute("precio"))));
		this.setRemovible(Boolean.parseBoolean(xmlElement.getAttribute("removible")));
		this.setAerodinamia(Integer.parseInt(xmlElement.getAttribute("aerodinamia")));
		
		this.parteInferior=Double.parseDouble(xmlElement.getAttribute("parteInferior"));
		this.parteSuperior=Double.parseDouble(xmlElement.getAttribute("parteSuperior"));
		this.largo=Double.parseDouble(xmlElement.getAttribute("largo"));
	}
	
	public double getLargo() {
		return largo;
	}
	public double getParteInferior() {
		return parteInferior;
	}
	public double getParteSuperior() {
		return parteSuperior;
	}
	
	public double funcionar () throws eParteNoFunciona{
		this.gastar();
		double coef=((this.largo*(this.parteInferior-this.parteSuperior))/100);
		if (coef<=0)return 0;
		else
			return coef;
	}
		
	public Element toXml(Document doc) {
		Element xmlElement = doc.createElement("parte");
		xmlElement.setAttribute("Clase","aleron");
		
		xmlElement.setAttribute("maxVU", ""+ this.getMaxVU());
		xmlElement.setAttribute("vidaUtil", ""+this.getVidaUtil());
		xmlElement.setAttribute("peso", ""+this.getPeso());
		xmlElement.setAttribute("aportevmax", ""+ this.aportevmax());
		xmlElement.setAttribute("detalle", this.getDetalle());
		xmlElement.setAttribute("precio", ""+(this.getPrecio()).getMonto());
		xmlElement.setAttribute("removible", ""+this.esRemovible());
		xmlElement.setAttribute("aerodinamia", ""+this.getAerodinamia());
		
		xmlElement.setAttribute("parteInferior", ""+this.parteInferior);
		xmlElement.setAttribute("parteSuperior", ""+this.parteSuperior);
		xmlElement.setAttribute("largo", ""+this.largo);
				
		return xmlElement;
	}
	
}
